package com.example.myproject;

import com.example.myproject.jackson.*;

import com.example.myproject.util.CryptoUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;

import com.spring.reject.ImportBeanDefinitionRegistrar.demo1.FooImportBeanDefinitionRegistrar;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Executors;

@SpringBootApplication
@MapperScan(basePackages="com.example.myproject.mapper")
@EnableRabbit
//@Import(value = {ShiroConfiguration.class})
//@Import(value = {AmqpConfig.class})
//示Mybatis的映射路径（package路径）
@Import({
		FooImportBeanDefinitionRegistrar.class})
public class Application  {



	public static void main(String[] args) {
		System.out.println("decode:"+CryptoUtil.decode("5sn1CMmT8T2D1+zNnxU8cg=="));
		//SpringApplication.run(Application.class, args);
		//14:56, dtea:Sun Jul 14 15:52:01 CST 2019
		//15:59 创建， tirggerDate 1563091500000

		//添加进入之后的更新时间， 1563091382268 16:03 ,预计16:05 执行，16:13执行了。


//		ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
//		String[] beanNames = context.getBeanDefinitionNames();
//		for (String beanName : beanNames) {
//			if(beanName.equals("foo")){
//				System.out.println("beanName:0="+beanName);
//				//context.getBean()
//			}
//		}
	}

	@Bean
	public MappingJackson2HttpMessageConverter getMappingJackson2HttpMessageConverter() {
		MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
		//设置日期格式
		ObjectMapper objectMapper = new ObjectMapper();
		SimpleDateFormat smt = new SimpleDateFormat("yyyy-MM-dd");
		objectMapper.setDateFormat(smt);
		SimpleModule module = new SimpleModule();
		module.addDeserializer(Integer.class, new JacksonIntegerDeSerializer());
		module.addDeserializer(Long.class, new JacksonLongDeSerializer());
		module.addDeserializer(Float.class, new JacksonFloatDeSerializer());
		module.addDeserializer(Double.class, new JacksonDoubleDeSerializer());
		module.addDeserializer(BigDecimal.class, new JacksonBigDeceimalDeSerializer());
		module.addDeserializer(Date.class, new JacksonDateDeSerializer());
		module.addDeserializer(String.class, new JacksonStringDeserializer());
		objectMapper.registerModule(module);
		mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper);

		//设置中文编码格式
		List<MediaType> list = new ArrayList<MediaType>();
		list.add(MediaType.APPLICATION_JSON_UTF8);
		mappingJackson2HttpMessageConverter.setSupportedMediaTypes(list);
		return mappingJackson2HttpMessageConverter;
	}


}